package cn.edu.gench.learn.controller;

import cn.edu.gench.learn.model.City;
import cn.edu.gench.learn.model.District;
import cn.edu.gench.learn.model.Province;
import cn.edu.gench.learn.service.CityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Administrator on 2017/5/3.
 */
@Controller
@RequestMapping("/city")
public class CityController {

    @Autowired
    private CityService cityService;

    @Service
    public class CityService {

    }

    @RequestMapping("/query")
    @ResponseBody
    public Map query(HttpServletRequest request){

        String pid = request.getParameter("pid");
        String cid = request.getParameter("cid");
        List<Province> proviceList = cityService.getAllProvince();
        List<City> cityList = cityService.getCityByPid(pid);
        List<District> disctList = cityService.getDistrictByCid(cid);

        Map<String,Object> map = new HashMap<String,Object>();
        map.put("p",proviceList);
        map.put("c",cityList);
        map.put("d",disctList);
        return  map;
    }


    /**'
     *
     * 查询所有的省城
     *
     * 根据省城ID 查询所有的市
     *
     * 根据城市ID查询所有的区域
     *
     *
     *
     */
    @RequestMapping("/test")
    public ModelAndView test(HttpServletRequest request){
        String pId = request.getParameter("p_id");
        String cId = request.getParameter("c_id");
        System.out.println(pId);
        System.out.println(pId);

        return new ModelAndView("index");
    }



}
